package com.hbnu.iostream;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

/**
 * @author kittychen
 * @date 2025-09-30 11:21
 */
public class InputStreamDemo02 {

    public static void main(String[] args) {
        String path = "E:" + File.separator + "2309" + File.separator + "test1.txt";
        File file = new File(path);

        InputStream inputStream = null;

        try {
            inputStream = new FileInputStream(file);

            byte[] bytes = new byte[1024];
            int len = 0;
            int temp = 0;
            while ((temp = inputStream.read()) != -1) {
                bytes[len++] = (byte) temp;
            }

            System.out.println(new String(bytes, 0, len));
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (inputStream != null) {
                    inputStream.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
